package com.pureut.equipment.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.equipment.domain.dto.MaintenanceProjectDto;
import com.pureut.equipment.domain.vo.MaintenanceProjectVo;
import com.pureut.equipment.service.MaintenanceProjectService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/***
 *
 * Author: 保养项目控制层
 * Date:2023/04/23 13:10
 * @DESC
 */
@RestController
@RequestMapping("/maintenance-project")
public class MaintenanceProjectController extends BaseController {

    /**
     * 保养项目service
     */
    @Resource
    MaintenanceProjectService maintenanceProjectService;

    /**
     * 保养项目列表
     */
    @RequiresPermissions("device:maintenance:project:list")
    @GetMapping("/list")
    public TableDataInfo list(MaintenanceProjectVo maintenanceProjectVo) {
        startPage();
        List<MaintenanceProjectDto> list = maintenanceProjectService.getList(maintenanceProjectVo);
        return getDataTable(list);
    }

    /**
     * 新增
     */
    @RequiresPermissions("device:maintenance:project:add")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody MaintenanceProjectVo maintenanceProjectVo) throws Exception {
        return toAjax(maintenanceProjectService.add(maintenanceProjectVo));
    }

    /**
     * 删除
     */
    @RequiresPermissions("device:maintenance:project:remove")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{id}")
    public AjaxResult removeMaintenanceProject(@PathVariable("id") Long id) {
        return toAjax(maintenanceProjectService.deleteMaintenanceProjectById(id));
    }

    /**
     * 查看
     */
    @RequiresPermissions("device:maintenance:project:query")
    @GetMapping("/getView/{id}")
    public AjaxResult getView(@PathVariable("id") Long id) {
        return AjaxResult.success(maintenanceProjectService.getView(id));
    }

    /**
     * 修改
     */
    @RequiresPermissions("device:maintenance:project:edit")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult update(@RequestBody MaintenanceProjectVo maintenanceProjectVo) {
        return AjaxResult.success(maintenanceProjectService.updateMaintenanceProject(maintenanceProjectVo));
    }
}
